package demo

import (
	"cow_golang/shared_mod/tcplib"
	"log"
)

// cmd/server/main.go
func main() {
	// 初始化路由
	router := router.NewRouter()

	// 注册安全类型处理
	router.Register(1001, func(c *conn.TCPConn, req *proto.LoginReq) {
		log.Printf("收到登录请求: %+v", req)
		resp := &proto.LoginResp{Code: 200}
		c.Send(1002, resp)
	})

	codec := &codec.LengthHeaderCodec{
		TypeResolver: func(id uint32) proto.Message {
			switch id {
			case 1001:
				return &proto.LoginReq{}
			case 1002:
				return &proto.LoginResp{}
			}
			return nil
		},
	}

	server := tcplib.NewServer(":8080", codec, router)
	log.Fatal(server.ListenAndServe())
}
